﻿using habbo.Kernel.Commons;
using habbo.Kernel.Storage.Querys;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace habbo.Habbo.Characters
{
    public class Character
    {
        /// <summary>
        /// Id of the character.
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// Username of the character.
        /// </summary>
        public string Username { get; private set; }

        /// <summary>
        /// Motto of the character.
        /// </summary>
        public string Motto { get; private set; }

        /// <summary>
        /// Figure of the character.
        /// </summary>
        public string Figure { get; private set; }

        /// <summary>
        /// Gender of the character.
        /// </summary>
        public string Gender { get; private set; }

        /// <summary>
        /// RealName of the character.
        /// </summary>
        public string RealName { get; private set; }

        /// <summary>
        /// CreditBalance of the character
        /// </summary>
        public int CreditBalance { get; private set; }

        /// <summary>
        /// LastLogin of the character
        /// </summary>
        public string LastLogin { get; private set; }

        /// <summary>
        /// MessengerFriends of the character.
        /// </summary>
        public ICollection<int> MessengerFriends { get; private set; }

        public Character(DataRow Row)
        {
            using (RowAdapter Adapter = new RowAdapter(Row))
            {
                this.Id = Adapter.PopInt32("id");
                this.Username = Adapter.PopString("username");
                this.Motto = Adapter.PopString("motto");
                this.Figure = Adapter.PopString("figure");
                this.Gender = Adapter.PopString("gender");
                this.RealName = Adapter.PopString("realname");
                this.CreditBalance = Adapter.PopInt32("credit_balance");
                this.LastLogin = Adapter.PopString("last_login");
            }
        }

        public void OnLogin()
        {
            //Console.WriteLine("{0} signed in.", Username);
            SystemApp.ConsoleSystem.PrintLine(this.GetType().Name.ToUpper(), "{0} signed in", Username);

            SystemApp.HabboSystem.MessengerManager.ParseStatus(Id);

            if (SystemApp.HabboSystem.CharacterManager.WeakSQLCache.ContainsKey(Id))
            {
                SystemApp.HabboSystem.CharacterManager.WeakSQLCache.Remove(Id);
            }
        }

        public void UpdateMessengerFriends(ICollection<int> Obj)
        {
            this.MessengerFriends = Obj;
        }
    }

    public enum GenderType
    {
        M, F
    }
}
